<?php

/**
 * This is the model class for table "{{kit_languages}}".
 *
 * The followings are the available columns in table '{{kit_languages}}':
 * @property integer $id
 * @property string $keyword
 * @property string $value
 * @property string $lang_group
 * @property string $module
 * @property integer $type
 * @property integer $active
 */
class BaseLanguages extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return BaseLanguages the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{kit_languages}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('type, active', 'numerical', 'integerOnly'=>true),
			array('keyword', 'length', 'max'=>255),
			array('lang_group, module', 'length', 'max'=>20),
			array('value', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, keyword, value, lang_group, module, type, active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'keyword' => 'Keyword',
			'value' => 'Value',
			'lang_group' => 'Lang Group',
			'module' => 'Module',
			'type' => 'Type',
			'active' => 'Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
        
        // Ajax filter
        $this->lang_group = (Yii::app()->user->getState('languageGroup') != '') ? Yii::app()->user->getState('languageGroup') : null;
        $this->module = (Yii::app()->user->getState('languageModule') != '') ? Yii::app()->user->getState('languageModule') : null;

        if (Yii::app()->user->getState('languageKeyword') != '') {
            $criteria->condition = 'keyword LIKE :keyword';
            $criteria->params = array(':keyword'=>'%'.Yii::app()->user->getState('languageKeyword').'%');
        }

		$criteria->compare('id',$this->id);
		//$criteria->compare('keyword',$this->keyword,true);
		$criteria->compare('value',$this->value,true);
		$criteria->compare('lang_group',$this->lang_group,true);
		$criteria->compare('module',$this->module,true);
		$criteria->compare('type',$this->type);
		$criteria->compare('active',$this->active);

		//return new CActiveDataProvider($this, array(
		//	'criteria'=>$criteria,
		//));
        return new CActiveDataProvider($this,array(
            'criteria'=>$criteria,            
            'pagination'=>array(                
                'pageSize'=>Yii::app()->user->getState('pageSize', 20),
                'pageVar'=>'page'),  
            'sort'=>array(
                'defaultOrder'=>'id ASC',
            ),           
        ));
	}
}